<?php

/**
 * Erra_Fields_TextArea - Textarea field
 *
 * @package
 * @author Alexis Eric
 * @copyright Copyright (c) 2012 - Erra Prod
 * @version $1.0$
 * @access public
 */
class Erra_Fields_TextArea extends Erra_Fields_Base_Field {
    protected $cols = null;
    protected $rows = null;
    protected $limit = null;

    function __construct($objectId, $cols=null, $rows=null) {
        parent::__construct($objectId);
        $this->cols = is_numeric($cols) ? $cols : 30;
        $this->rows = is_numeric($rows) ? $rows : 5;
        $this->setDatabaseType('text', 0);
    }

    /**
     * Erra_Fields_TextArea::editInstance() - Shows a textarea
     *
     * @param mixed $lang
     * @return
     */
    public function editInstance(Array $extraProperties=null) {
        $res = '<div class="erra-form-field-instance">';
        $res .= $this->outputFieldHeader();
        $jsLimit = is_numeric($this->limit) ? 'onKeyDown="limitTextArea(this,' . $this->limit . ');" onKeyUp="limitTextArea(this,' . $this->limit . ');"' : '';
        $res .= '<textarea '.$this->getHtmlAttributes($extraProperties).' cols="' . $this->cols . '" rows="' . $this->rows . '" name="' . $this->getHtmlName() . '" id="' . $this->getHtmlId() . '" ' . $jsLimit . '>' . $this->getRawData() . '</textarea>';
        $res .= '</div>';
        return $res;
    }

    function toHtml($displayParameters=null) {
        return $this->getRawData();
    }

    /** Getters and setters * */
    public function getCols() {
        return $this->cols;
    }

    public function setCols($cols) {
        $this->cols = $cols;
        return $this;
    }

    public function getRows() {
        return $this->rows;
    }

    public function setRows($rows) {
        $this->rows = $rows;
        return $this;
    }

    public function getLimit() {
        return $this->limit;
    }

    public function setLimit($limit) {
        $this->limit = $limit;
        return $this;
    }

}